package com.dameng.jianyouquan.mvp.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.dameng.jianyouquan.R;
import com.dameng.jianyouquan.base.mvpBase.BaseMvpActivity;
import com.dameng.jianyouquan.base.mvpBase.BasePresenter;
import com.dameng.jianyouquan.mvp.model.RegisterModel;
import com.dameng.jianyouquan.mvp.presenter.impl.RegisterPresenterImpl;
import com.dameng.jianyouquan.mvp.view.view.RegisterView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RegisterActivity extends BaseMvpActivity implements RegisterView {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.et_register_phone)
    EditText etRegisterPhone;
    @BindView(R.id.et_register_verification_code)
    EditText etRegisterVerificationCode;
    @BindView(R.id.btn_register_send_verification_code)
    Button btnRegisterSendVerificationCode;
    @BindView(R.id.et_register_pwd)
    EditText etRegisterPwd;
    @BindView(R.id.btn_register)
    Button btnRegister;
    private RegisterPresenterImpl registerPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected BasePresenter createPresenter() {
        registerPresenter = new RegisterPresenterImpl(this, new RegisterModel());
        return registerPresenter;
    }


    @OnClick({R.id.iv_back, R.id.btn_register_send_verification_code, R.id.btn_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_register_send_verification_code:
                registerPresenter.sendVerificationCode(etRegisterPhone.getText().toString().trim());
                break;
            case R.id.btn_register:
                registerPresenter.register(etRegisterPhone.getText().toString().trim(),etRegisterVerificationCode.getText().toString().trim(),etRegisterPwd.getText().toString().trim());
                break;
        }
    }

    @Override
    public void registerSuccess() {
        showToast("注册成功");
        finish();
        startActivity(new Intent(RegisterActivity.this,ChooseIdentityActivity.class));
        //进入选择身份页面
    }

    @Override
    public void registerFail(String msg) {
        showToast(msg);
    }

    @Override
    public void sendVerificationCodeSuccess() {
        showToast("验证码已发送");
    }

    @Override
    public void sendVerificationCodeFail(String msg) {
        showToast(msg);
    }
}
